# === 链式前向星 ===
# 作用: 存储图的数据结构
# author:Rainboy
# update: 2020-10-19 11:49

snippet linkList "链式前向星" b
struct linkList {
    typedef struct {int u,v,w,next;} edge;
    edge e[maxe];
    int h[maxn],edge_cnt=0;
    linkList(){	//构造函数
        edge_cnt=0;
        memset(h,-1,sizeof(h));
    }
    void add(int u,int v,int w=0){
        e[edge_cnt] = {u,v,w,h[u]};
        h[u] = edge_cnt++;
    }
    void add2(int u,int v,int w=0){
        add(u,v,w);
        add(v,u,w);
    }
    edge& operator[](int i){
        return e[i];
    }
} e;
endsnippet

snippet ef "linkList forEach" b
for(${1:i}=${3:e}.h[${2:u}];~$1;i=$3[$1].next){
	int &v = $3[$1].v, &w = $3[$1].w;
	$0
}
endsnippet

snippet ief "linkList forEach with int" b
for(int ${1:i}=${3:e}.h[${2:u}];~$1;i=$3[$1].next){
	int &v = $3[$1].v, &w = $3[$1].w;
	$0
}
endsnippet
